require "Q2DViewer"

---------------------------------------------------------------------------------------------
--图像设置
function set_graph( self )
	 self.gp:setLineWidth( self.linewidth or 3 );
	 if self.name then self.gp:setName( self.name ) end;
	 if self.color then self.gp:setColor( self.color[1] or 1, self.color[2] or 0, self.color[3] or 0 ) end;
end

---------------------------------------------------------------------------------------------
--图像设置
function addGraph( self, x, y ,label)
	 local xd = std.vector:new();
	 local yd = std.vector:new();
	 assert( #x==#y, "size don't math" );
	 assert( #x>0 , "array is empty" )
	 for _,v in pairs(x) do
		xd:push_back(v);
	end
	for _,v in pairs(y) do
		yd:push_back(v);
	end
	
	local gp;
	if label~=nil then
	      gp = self:addGraph(xd,yd,label)
	else
	      gp =  self:addGraph(xd,yd);
	end
	return gp;
end

function set_view( self )
	 if self.legendfontsize~=nil then
		set_legend_font_size(self)
	 end
end

function set_legend_font_size( self )
	font = self.view:legend():font()
	font:setPointSize(self.legendfontsize);
	self.view:legend():setFont(font);
end
function set_axis_width( self )
	local basePen = self.axis:basePen();
	local tickPen = self.axis:tickPen();
	basePen:setWidth( self.linewidth or 3 );
	tickPen:setWidth( self.linewidth or 3 );
	
	local selBasePen = self.axis:selectedBasePen();
	local selTickPen = self.axis:selectedTickPen();
	selBasePen:setWidth( self.linewidth or 3 );
	selTickPen:setWidth( self.linewidth or 3 );
	
	self.axis:setBasePen(basePen);
	self.axis:setTickPen(tickPen);
	self.axis:setSelectedBasePen(selBasePen);
	self.axis:setSelectedTickPen(selTickPen);
end
function set_axis_lable_font_size( self )
	font = self.axis:labelFont()
	font:setPointSize(self.fontsize);
	self.axis:setLabelFont(font);
	
		
	font = self.axis:selectedLabelFont()
	font:setPointSize(self.fontsize);
	self.axis:setSelectedLabelFont(font);
end

function set_axis_tick_font_size( self )
	font = self.axis:tickLabelFont()
	font:setPointSize(self.tickfontsize);
	self.axis:setTickLabelFont(font);
	
	font = self.axis:selectedTickLabelFont()
	font:setPointSize(self.tickfontsize);
	self.axis:setSelectedTickLabelFont(font);
	
end



function set_axis( self )
	if self.linewidth ~= nil then set_axis_width(self) end
	if self.fontsize ~= nil then set_axis_lable_font_size(self) end
	if self.tickfontsize ~= nil then set_axis_tick_font_size(self) end
	if self.lablecolor ~= nil then self.axis:setLabelColor( c ) end
	if self.name ~= nil then self.axis:setLabel( self.name ) end
	if self.subgridvisiable ~= nil then 
		print( "set subgridvisiable:", self.subgridvisiable );
		self.axis:grid():setSubGridVisible( self.subgridvisiable ) 
	end
	if self.range ~= nil and self.range[1] and self.range[2] then 
		print( "set range:", self.range[1],self.range[2] );
		self.axis:setRange( self.range[1],self.range[2] ) 
	end
	if self.tickcount ~= nil then
		self.axis:setTickCount( self.tickcount )
	end
end
---------------------------------------------------------------------------------------------